import { RouterProvider } from "react-router-dom";
import routes from "./router";
import { Suspense, useEffect, react } from "react";
import "./App.less";
import "@/common/i18n/i18n";
import { setLangs } from "./utils/localStorage";
import { useTranslation } from "react-i18next";
import { useAppDispatch } from "./hooks/useAppDispatch";
import { fetchConfig, fetchUserInfo } from "./store/slices/userInfo";
import { checkLang } from "./api/module/user";
function App() {
  const dispatch = useAppDispatch();

  const { i18n } = useTranslation();
  // const testFetch = async () => {
  //   const html = await fetch('/?_timestamp=' + Date.now()).then((resp) =>
  //     resp.text()
  //   );
  // };
  // testFetch();
  const reqCheckLang = async () => {
    const res = await checkLang();
    if (res.code === 0) {
      i18n.changeLanguage(res.data.lang.split("-")[0]);
      setLangs(res.data.lang.split("-")[0]);
    }
  };
  useEffect(() => {
    reqCheckLang();
    // dispatch(fetchUserInfo());
    // dispatch(fetchConfig());
  }, []);
  return (
    <>
      {/* <React.StrictMode> */}
      <Suspense
        fallback={
          <div className="h-screen flex justify-center items-center">
            <svg
              className="animate-spin h-5 w-5 mr-3 ..."
              viewBox="0 0 24 24"
            ></svg>
          </div>
        }
      >
        <RouterProvider router={routes} />
        {/* <div className="text-white-1">{t('U2U')}</div> */}
      </Suspense>
      {/* </React.StrictMode> */}
    </>
  );
}

export default App;
